package com.example.myapplication.base;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;


/**
 * Created by Administrator on 2018/3/25.
 */

public abstract class BaseActivity extends AppCompatActivity {
    @SuppressLint("SourceLockedOrientationActivity")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (createLayout() != 0)
        setContentView(createLayout());
    }


    public boolean getBarColor() {
        return false;
    }

    /**
     * 是否自定义bar
     *
     * @return
     */
    public boolean isCustomStatusBar() {
        return false;
    }




    @Override
    protected void onPostCreate(@Nullable Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        initViews();
        initData();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    /**
     * @return 用来加载布局文件
     */
    protected abstract int createLayout();

    /**
     * 初始化视图
     */
    public void initViews() {

    }

    /**
     * 初始化数据
     */
    public void initData() {
    }

    /**
     * @param cls
     * @param bundle 界面跳转
     */
    public void startActivity(Class cls, Bundle bundle) {
        Intent intent = new Intent(this, cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }


    /**
     * @param cls 界面跳转，不需要Bundle传值
     */
    public void startActivity(Class cls) {
        startActivity(cls, null);
    }

    /**
     * @param cls
     * @param bundle
     * @param code   界面跳转，带请求码
     */
    public void startActivityForResult(Class cls, Bundle bundle, int code) {
        Intent intent = new Intent(this, cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivityForResult(intent, code);
    }

    //全局定义
    private long lastClickTime = 0L;
    // 两次点击间隔不能少于1000ms
    private static final int FAST_CLICK_DELAY_TIME = 1000;


    public void onClick(View view) {
        if (System.currentTimeMillis() - lastClickTime < FAST_CLICK_DELAY_TIME) {
            return;
        }
        lastClickTime = System.currentTimeMillis();
        onClicks(view);
    }

    public void onClicks(View view) {

    }

}